package com.dreamchaser.loginTest.servlet;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 需要敏感词过滤的接口
 */
public class WordServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //因为servlet并没有setParameter方法（这是故意的），所以过滤后word无法通过getparameter来获取
        //所以一般有两种方法一种把它放在attribute里，一种重写Request类，不过这会很麻烦
        String word= String.valueOf(req.getAttribute("word"));
        ServletOutputStream outputStream = resp.getOutputStream();
        String result="词汇已净化，请放心食用："+word;
        outputStream.write(result.getBytes());
    }
}
